// 引入路由组件与组件
// 路由懒加载
const Home = () =>
    import ('@/pages/Home/index');
const Login = () =>
    import ('@/pages/Login/index');
const Register = () =>
    import ('@/pages/Register/index');
const Search = () =>
    import ('@/pages/Search/index');
const Detail = () =>
    import ('@/pages/Detail/index');
import AddCartSuccess from '@/pages/AddCartSuccess/index';
import ShopCart from '@/pages/ShopCart/index';
import Trade from '@/pages/Trade/index';
import Pay from '@/pages/Pay/index';
import PaySuccess from '@/pages/PaySuccess/index';
import Center from '@/pages/Center/index';
// 引入二级路由组件
import MyOrder from '@/pages/Center/MyOrder/index';
import GroupOrder from '@/pages/Center/GroupOrder/index';

export default [{
        path: '/home',
        component: Home,
        meta: {
            showFooter: true,
        },
        name: 'Home'
    },
    {
        path: '/center',
        component: Center,
        meta: {
            showFooter: true
        },
        name: 'Center',
        // 二级路由组件
        children: [{
                path: 'myorder', //不用写斜杠/myorder
                component: MyOrder,
                name: 'MyOrder',
            },
            {
                path: 'grouporder', //不用写斜杠/myorder
                component: GroupOrder,
                name: 'GroupOrder',
            },
            {
                path: '/center',
                redirect: '/center/myorder'
            }
        ]
    },
    {
        path: '/detail/:skuId?',
        component: Detail,
        meta: {
            showFooter: true
        },
        name: 'Detail'
    },
    {
        path: '/search/:keyword?',
        name: "Search",
        component: Search,
        meta: {
            showFooter: true
        },
        // props: true
        // props: { a: 1, b: 2 },
        props({ query: { k }, params: { keyword } }) {
            return { k, keyword }
        }
    },
    {
        path: '/register',
        component: Register,
        meta: {
            showFooter: false
        },
        name: 'Register'
    },
    {
        path: '/login',
        component: Login,
        name: 'Login',
        meta: {
            showFooter: false
        }
    },
    {
        path: '/addcartsuccess',
        name: 'AddCartSuccess',
        component: AddCartSuccess,
        meta: {
            showFooter: true
        },
    },
    {
        path: "/shopcart",
        name: 'ShopCart',
        component: ShopCart,
        meta: {
            showFooter: true
        },
    },
    {
        path: '/trade',
        component: Trade,
        name: 'Trade',
        meta: {
            showFooter: true
        },
        // 路由独享守卫
        beforeEnter(_, from, next) {
            // 判断来源是不是shopcart
            if (from.name == 'ShopCart')
            // 如果是从购物车而来,就允许通过
                next();
            else {
                next(false);
                // 中断当前的导航,如果浏览器的URL改变了(可能是用户手动或者点击浏览器后退按钮),
                // 那么url地址会重置到from路由对于的地址
            }
        }
    },
    {
        path: '/pay',
        name: 'Pay',
        component: Pay,
        meta: {
            showFooter: true
        },
        // 路由独享守卫
        beforeEnter(_, from, next) {
            // 判断来源是不是Trade
            if (from.name == 'Trade')
            // 如果是从Trade而来,就允许通过
                next();
            else {
                next(false);
                // 中断当前的导航,如果浏览器的URL改变了(可能是用户手动或者点击浏览器后退按钮),
                // 那么url地址会重置到from路由对于的地址
            }
        }
    },
    {
        path: '/paysuccess',
        name: 'PaySuccess',
        component: PaySuccess,
        meta: {
            showFooter: true
        }
    },
    // 重定向，在项目跑起来的时候，访问/立马定向到首页
    {
        path: '/',
        redirect: "/home",
    }

]